import axios from 'axios';
import VueAxios from 'vue-axios'
import qs from 'qs'
import store from '../vuex/store'
axios.interceptors.request.use(
    config => {
        if (store.state.auth.token) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
            config.headers['x-access-token'] = store.state.auth.token;
        }
        return config;
    });

let base="http://localhost:9000/api";

let Api={
    //banner
    getBanner:function (params) {
        return axios.get(base+`/banner`,{params:{params}});
    },
    updateBanner:function (params) {
        console.log(params);
        return axios.post(base+`/banner/index`,params);
    },
    deleteBanner:function (id) {
        return axios.post(base+`/banner/delete/`+id);
    },
    searchBanner:function (keyword) {
        return axios.get(base+`/banner/search?keywords=`+keyword);
    },
    createBanner:function (params) {
        return axios.post(base+'/banner/create',params);
    },
    //wishpool
    getWishpool:function (params) {
        return axios.get(base+`/wishpool`,{params:{params}});
    },
    updateWishpool:function (params) {
        console.log(params);
        return axios.post(base+`/wishpool/index`,params);
    },
    deleteWishpool:function (id) {
        return axios.post(base+`/wishpool/delete/`+id);
    },
    searchWishpool:function (keyword) {
        return axios.get(base+`/wishpool/search?keywords=`+keyword);
    },
    createWishpool:function (params) {
        return axios.post(base+'/wishpool/create',params);
    },

    //sysnews
    getSysnews:function (params) {
        return axios.get(base+`/sysnews`,{params:{params}});
    },
    updateSysnews:function (params) {
        console.log(params);
        return axios.post(base+`/sysnews/index`,params);
    },
    deleteSysnews:function (id) {
        return axios.post(base+`/sysnews/delete/`+id);
    },
    searchSysnews:function (keyword) {
        return axios.get(base+`/sysnews/search?keywords=`+keyword);
    },
    createSysnews:function (params) {
        return axios.post(base+'/sysnews/create',params);
    },

    //bbsnews
    getBbsnews:function (params) {
        return axios.get(base+`/bbsnews`,{params:{params}});
    },
    updateBbsnews:function (params) {
        console.log(params);
        return axios.post(base+`/bbsnews/index`,params);
    },
    deleteBbsnews:function (id) {
        return axios.post(base+`/bbsnews/delete/`+id);
    },
    searchBbsnews:function (keyword) {
        return axios.get(base+`/bbsnews/search?keywords=`+keyword);
    },
    createBbsnews:function (params) {
        return axios.post(base+'/bbsnews/create',params);
    },

    //activity
    getActivity:function (params) {
        return axios.get(base+`/activity`,{params:{params}});
    },
    updateActivity:function (params) {
        console.log(params);
        return axios.post(base+`/activity/index`,params);
    },
    deleteActivity:function (id) {
        return axios.post(base+`/activity/delete/`+id);
    },
    searchActivity:function (keyword) {
        return axios.get(base+`/activity/search?keywords=`+keyword);
    },
    createActivity:function (params) {
        return axios.post(base+'/activity/create',params);
    },

    //community
    getCommunity:function (params) {
        return axios.get(base+`/community`,{params:{params}});
    },
    updateCommunity:function (params) {
        console.log(params);
        return axios.post(base+`/community/index`,params);
    },
    deleteCommunity:function (id) {
        return axios.post(base+`/community/delete/`+id);
    },
    searchCommunity:function (keyword) {
        return axios.get(base+`/community/search?keywords=`+keyword);
    },
    createCommunity:function (params) {
        return axios.post(base+'/community/create',params);
    },
    listCommunity:function () {
        return axios.get(base+'/community/list');
    },

    authLogin:function (params) {
        return axios.post('http://localhost:9000'+'/auth/authorize/index',params);
    },
    getUserInfo:function () {
        return axios.get(base+'/user/index');
    }

};


export default Api;
